import Vue from 'vue'
import Router from 'vue-router'
import dashboard from '@/router/modules/dashboard '
// 审批
import approvals from '@/router/modules/approvals'
// 考勤
import attendances from '@/router/modules/attendances'
//  组织架构
import departments from '@/router/modules/departments'
// 员工
import employees from '@/router/modules/employees'
// 权限管理
import permission from '@/router/modules/permission'
// 工资
import salarys from '@/router/modules/salarys'
// 公司设置
import setting from '@/router/modules/setting'
// 社保
import social from '@/router/modules/social'
import Layout from '@/layout'
Vue.use(Router)
// 动态路由表
export const asyncRoutes = [
  //  组织架构
  departments,
  // 审批
  approvals,
  // 考勤
  attendances,

  // 员工
  employees,
  // 权限管理
  permission,
  // 工资
  salarys,
  // 公司设置
  setting,
  // 社保
  social
]
/* Layout */
// import Layout from '@/layout'
// 静态路由
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/import',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        name: 'import',
        component: () => import('@/views/impot/index'),
        meta: { title: '文件导入', icon: 'dashboard' }
      }
    ]
  },
  dashboard
  // 审批

  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: [...constantRoutes]
  })

const router = createRouter()
// 给routes添加新的路由规则
// router.addRoutes([...asyncRoutes])
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
